package cn.jit.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.jit.dao.ExamQuestionDao;
import cn.jit.po.ExamQuestion;
import cn.jit.po.Question;
import cn.jit.service.ExamQuestionService;

@Service("examQuestionService")
public class ExamQuestionServiceImpl implements ExamQuestionService{
	
	@Resource
    private ExamQuestionDao examQuestionDao;
	

	@Override
	public List<ExamQuestion> getExamQuestions(ExamQuestion examQuestion) {
		
		return examQuestionDao.getExamQuestions(examQuestion);
	}


	@Override
	public int addExamQuestion(ExamQuestion examQuestion) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("examId", examQuestion.getExamId());
		List<Question> qsList = examQuestion.getQuestionList();
		for (Question qs : qsList) {
			if (qs.getUserAnswer().equals(qs.getQuestionAnswer())) {
				qs.setIsRight(1);
			} else {
				qs.setIsRight(0);
			}
		}
		map.put("qsList", qsList);		
		
		System.out.println("in service: ");
		System.out.println(qsList);
		
		return examQuestionDao.addExamQuestion(map);
	}
	
	
	
	
}
